package com.my.myrecorder;

import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

/**
 * Created by 张英杰 on 2016/10/14.
 */
public class TestHandler extends AppCompatActivity {

    private TextView tv;
    private long mStartTime;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_form);
        Log.i("TestHandler====","TestHandler");

        findViewById(R.id.startRecorder).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mStartTime = System.currentTimeMillis();
                handler.postDelayed(runnable,1000);
            }
        });
        //结束
        findViewById(R.id.overRecorder).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                handler.removeCallbacks(runnable);
            }
        });
        tv = (TextView) findViewById(R.id.tvRecorderInfo);
    }
    Handler handler = new Handler(){};
    Runnable runnable= new Runnable() {
        @Override
        public void run() {
            long endTime = System.currentTimeMillis();
            int mTime = (int) ((endTime - mStartTime) / 1000);
            tv.setText(mTime + "" + '"');
            handler.postDelayed(runnable,1000);
        }
    };
}
